package com.example.run_game;

import android.util.Log;

public class AchievementManager
{
	private DbManager db;
	Achievement[] achievements;
	
    AchievementManager(DbManager db)
    {
    	this.db = db;
    	achievements = db.getAchievements();
    	//for(int i=0; i< achievements.length; i++)
    	  //Log.d("GAME:", "Copied Achievement: " + achievements[i].id + " " + achievements[i].name + " " + achievements[i].dateUnlocked);
    }

	public void saveAchievements()
	{
		db.saveAchievements(achievements);		
	}

	public void testAchievements(Player player, double altGained, double speedOfRun, long timeOfRun, double distanceOfRun, Checkpoint[] allCkps, int weatherCode)
	{
		for(int i=0; i<achievements.length; i++)
			achievements[i].testInGame(player, altGained, speedOfRun, timeOfRun, distanceOfRun, allCkps, weatherCode);
	}
	
	public void testAchievementsEndGame()
	{
		System.out.println("achievements: " +achievements.length);
		for(int i=0; i<achievements.length; i++)
			achievements[i].testEndGame();
	}
	
	public String isAchieved(String nameIn)
	{
		for(int i=0; i<achievements.length; i++)
		{
			if(achievements[i].name.equals(nameIn))
				return achievements[i].dateUnlocked;
		}
		return "";
	}
}
